import 'package:flutter/material.dart';

class CeHuaShanChu extends StatefulWidget {
  @override
  _CeHuaShanChuState createState() => _CeHuaShanChuState();
}

class _CeHuaShanChuState extends State<CeHuaShanChu>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  List needModelList = ['', '', ''];

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text('策划删除'),
          centerTitle: true,
        ),
      body: ListView.builder(
        itemCount: needModelList.length,
        itemBuilder: (context, index) {
          final item = needModelList[index];
          //通过拖动来删除小部件的widget
          return Dismissible(
              //如果Dismissible是一个列表项 它必须有一个key 用来区别其他项
              key: new Key(item),
              onDismissed: (direction) {
                needModelList.removeAt(index);
                //这个和Android的SnackBar差不多
                Scaffold.of(context).showSnackBar(
                    new SnackBar(content: new Text("$item dismissed")));
              }, //如果指定了background 他将会堆叠在Dismissible child后面 并在child移除时暴露
              background: new Container(
                color: Colors.red,
                child: Text('删除'),
              ),
              child: new Column(
                children: <Widget>[
                  Container(height: 44,child: Text('data')),
                  Container(height: 1, color: Color(0xffebebeb))
                ],
              ));
        },
      ),
    );
  }
}
